package com.jyh.config.quantity;


import java.lang.reflect.Field;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import com.jyh.util.ReflectUtils;

@Configuration
@PropertySource("classpath:app-config.properties")
public class StaticConfig {
	private final Logger logger = LoggerFactory.getLogger(StaticConfig.class);
	
	/** 短信发送请求地址 */
	@Value("${note.HttpSMSUrl}")
	private void NOTEHTTPSMSURL(String val){
		setConfig(Thread.currentThread().getStackTrace()[1].getMethodName(), val);
	}
	
	/**短信发送Token地址  */
	@Value("${note.HttpTokenUrl}")
	private void NOTEHTTPTOKENURL(String val){
		setConfig(Thread.currentThread().getStackTrace()[1].getMethodName(), val);
	}
	
	/**登录短信发送文本 */
	@Value("${note.SMS.text}")
	private void NOTESMSTEXT(String val){
		setConfig(Thread.currentThread().getStackTrace()[1].getMethodName(), val);
	}
	
	/**登录短信是否发送 1是 2否*/
	@Value("${note.SMS.is.send}")
	private void NOTESMSISSEND(String val){
		setConfig(Thread.currentThread().getStackTrace()[1].getMethodName(), val);
	}
	
	private void setConfig(String key, String val) {
		try {
			Field field = ConstantConfig.class.getDeclaredField(key);
			ReflectUtils.setFinalStatic(field, new String(val.getBytes("ISO-8859-1"), "UTF-8"));
			logger.info("加载配置：" + field.getName() + "=" + field.get(null));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
